package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import com.example.demo.mapper.UserMapper;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    CommandLineRunner demo(UserMapper userMapper) {
        return args -> {
            StringBuilder sb = new StringBuilder();
            sb.append("=== User Table Contents ===\n");
            userMapper.findAll().forEach(user -> sb.append(user.toString() + "\n"));
            System.out.println("\n" + sb.toString());
        };
    }
}
